package com.wangyadong.hobby.schedule.jobtask.tree.pq;

import java.util.Comparator;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/8/2813:03
 **/
public abstract class AbstractPriorityQueue<K, V> implements PriorityQueue<K, V> {
    private Comparator comp;
    public AbstractPriorityQueue(Comparator<K> comparator) {
        comp = comparator;
    }
    public AbstractPriorityQueue() {
        this(new DefaultComparator<K>());
    }
    protected int compare(Entry<K, V> a, Entry<K, V> b) {
        if(a.getKey()==null){
            System.out.println("a.getKey=" + a.getKey() + "\t\t" + "b.getKey()==" + b.getKey());
        }
        return comp.compare(a.getKey(), b.getKey());
    }
    public boolean checkKey(K k) {
        return (comp.compare(k, k) == 0);
    }
    public boolean isEmpty() {
        return size() == 0;
    }
    public static class PQEntry<K, V> implements Entry<K, V> {
        private K k;
        private V v;
        public PQEntry(K k1, V v1) {
            this.k = k1;
            this.v = v1;
        }
        @Override
        public K getKey() {
            return k;
        }
        @Override
        public V getValue() {
            return v;
        }
    }
}
